/*
 * 作者：刘时明
 * 时间：2020/3/6-21:47
 * 作用：
 */
package com.yidu.manage.service.system;

import com.yidu.manage.domain.model.LoginUser;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

@Component
public class CurrentUser
{
    public static LoginUser getCurrentUser()
    {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        if (authentication != null && authentication.getPrincipal() != null)
        {
            LoginUser sysUser = (LoginUser) authentication.getPrincipal();
            sysUser.setRoles(authentication.getAuthorities());
            System.out.println(sysUser);
            return sysUser;
        }
        return null;
    }
}
